package chat.user;

import java.io.Serializable;
import java.net.Socket;
import java.util.*;

public class Group implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String group_name;
	private Vector<User> user_list = new Vector<User>();
	private Vector<String> user_list_names = new Vector<String>();

	public boolean equals(Group g) {

		if (this.group_name.equalsIgnoreCase(g.getName())) {

			return true;
		}

		return false;
	}

	public Group(String name) {

		group_name = name;

	}

	public String getName() {

		return this.group_name;
	}

	public void addUser(User user) {

		this.user_list.add(user);
		this.user_list_names.add(user.getUserName());
	}

	public Vector<User> getUsers() {

		return this.user_list;
	}

	public Socket getSocket(User u) {

		Socket socket = null;

		for (User user : this.user_list) {

			if (user.equals(u)) {
				socket = user.getSocket();
			}

		}

		return socket;
	}

	public void removeUser(User u) {

		this.user_list.remove(u);
		this.user_list_names.remove(u.getUserName());
	}

	public Vector<User> getUserList() {

		return this.user_list;
	}

	public boolean isEmpty() {

		if (user_list.size() > 0)
			return false;
		else
			return true;

	}
	
	public Vector<String> getUserNames(){
		
		return this.user_list_names;
	}
	
	public User getUser(String user_name){
		
		User user = null;
		
		for (User u: user_list)
		{
			if (u.getUserName().equalsIgnoreCase(user_name)){
				user = u;
			}
		}
		
		return user;
	}
}
